require('ejs');
var MongoStore = require('express-session-mongo');
var Server = require('mongodb').Server;
var sessionStore;

exports.configure = function (app, express) {
    sessionStore = new MongoStore();
    app.configure(function () {
        app.use(express.cookieParser());
        app.use(express.session({
            store: sessionStore,
            secret: 'the greatest secret in the world',
            key: 'jsessionid'
        }));
        app.set('views', __dirname + '/../views');
        app.set('view engine', 'ejs');
        app.set('view options', {
            layout: false
        });

        app.use(express.static(__dirname + '/../public'));
        app.use(express.bodyParser());
    });

    app.configure('development',

    function () {
        app.use(express.errorHandler({
            dumpExceptions: true,
            showStack: true
        }));
    });

    app.configure('production',

    function () {
        app.use(express.errorHandler());
    });

    return sessionStore;
};